fix(hrp): symmetrise correlation distance before squareform (2.0.1)#13
Merged
Conversation
hrp() raised "ValueError: Distance matrix must be symmetric" when the correlation matrix was only symmetric to floating-point tolerance — the normal case for matrices coming from cov_to_corr or denoise_cov, where sub-epsilon asymmetry is unavoidable. Average the distance with its transpose and zero the diagonal before squareform; clustering is unchanged. Mirrors the same fix in RiskLabAI.jl v0.5.1. Adds a regression test (test_hrp_asymmetric_correlation) and bumps the patch version to 2.0.1. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
optimization.hrp.hrpraisedValueError: Distance matrix 'X' must be symmetricwhenever the input correlation matrix was only symmetric to floating-point tolerance. That is the normal case for correlation matrices produced bycov_to_corrordenoise_cov, where sub-epsilon asymmetry (~1e-16) is unavoidable. The failure surfaced while building the Python portfolio-construction tutorial (parity withNotebooks.jl).Fix
Symmetrise the correlation distance (
(d + dᵀ)/2, zero diagonal) beforescipy.spatial.distance.squareform. Clustering output is unchanged for genuinely symmetric input. This mirrors the same fix already shipped in RiskLabAI.jl v0.5.1 ((distance .+ distance') ./ 2).Tests
test_hrp_asymmetric_correlation(fails onmain, passes here).test/optimization/suite green (12 passed).Patch version bump 2.0.0 → 2.0.1; CHANGELOG updated.
🤖 Generated with Claude Code